package com.xinghai.system.mapper;

import java.util.List;
import com.xinghai.system.domain.QdUser;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 用户Mapper接口
 *
 * @author xinghai
 * @date 2024-12-04
 */
public interface QdUserMapper  extends BaseMapper<QdUser>
{

    @Update("update qd_user set team_num = team_num + #{teamNum}  where FIND_IN_SET(id,#{id})")
    boolean updateTeamNum(@Param("id") String id,@Param("teamNum") int teamNum);

    @Update("update qd_user set push_num = push_num + #{pushNum}  where FIND_IN_SET(id,#{id})")
    boolean updatePushNum(@Param("id") String id,@Param("pushNum") int pushNum);

    @Select("SELECT t2.id,t1.pid superId, t1.`level`FROM ( SELECT @r AS _id, ( SELECT @r := super_id FROM qd_user WHERE id = _id ) AS pid," +
            "@l := @l + 1 AS `level`  FROM ( SELECT @r := #{id}, @l := 0 ) vars, qd_user h WHERE @r <> 0 ) t1 JOIN qd_user t2 ON " +
            "t1._id = t2.id ORDER BY t1.`level`;")
    List<QdUser> getAllParentMemberById(String id);

    @Select("select get_child_list(#{userId})")
    String queryAllChild(String userId);
}
